package com.kbt.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.*;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.system.email.Email;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;
import com.google.gson.Gson;
import com.kbt.base.BaseApplication;
import com.kbt.commont.Constants;
import com.kbt.model.data.AddressBean;
import com.kbt.model.data.BaseBean;
import com.kbt.model.data.ShopCarBean;
import com.kbt.net.RequestManager;
import com.kbt.onekeyshare.OnekeyShare;
import com.kbt.onekeyshare.ShareContentCustomizeCallback;
import com.kbt.ui.CityPopWindow;
import com.kbt.util.tool.BtnSetting;
import com.kbt.util.utils.SharePreferenceUtils;
import com.kbt.util.utils.Utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.graphics.Matrix;

import javax.xml.namespace.QName;


public class WebViewActivity extends Activity implements RequestManager.ResponseInterface{

    private RequestManager mRequestManager;
    private Map<String, String> map =null;
    private SharePreferenceUtils share;
    private WebView webView;
    private String htmlurl;
    private String title;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.webview);
        this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.return_xinxi_title);
        BaseApplication.getInstance().addActivity(this);
        initTitle();
        init();
        initData();
    }
    //初始化标题
    private void initTitle(){

        //设置返回按钮事件,关闭当前Activity，返回数据
        ImageView returnImg = (ImageView) findViewById(R.id.return_btn);
        returnImg.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                BaseApplication.getInstance().removeActivity(WebViewActivity.this);
                finish();
            }
        });
        ImageView shareImg = (ImageView) findViewById(R.id.shareImgBtn);
        shareImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //打开分享链接
                showShare();
            }
        });

        TextView appTitleView = (TextView) findViewById(R.id.center_title);
        appTitleView.setText("豆花信息");
    }
    //初始化
    private void init(){
        htmlurl = getIntent().getStringExtra("html");
        title = getIntent().getStringExtra("title");
        mRequestManager = new RequestManager();
        mRequestManager.setResponseListener(this);
        map = new HashMap<String, String>();
    }
    //显示数据
    private void initData(){
//        String htmlData="<div style='width:100%;height:auto'><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=285814F073CA11E5AF1A00163E001C5F&amp;width=600&amp;height=93' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=286FE53A73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=90' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=28811DE673CA11E5AF1A00163E001C5F&amp;width=600&amp;height=93' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=28926FEC73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=84' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=28A08D0273CA11E5AF1A00163E001C5F&amp;width=600&amp;height=85' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=28BD1BDE73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=71' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=28D0A63673CA11E5AF1A00163E001C5F&amp;width=600&amp;height=79' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=28E8965673CA11E5AF1A00163E001C5F&amp;width=600&amp;height=84' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=28FBA58E73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=66' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=29352A5C73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=77' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=29441EFE73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=84' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=295A534A73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=88' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=2995AE9A73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=71' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=29A985AA73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=81' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=29BEFAB673CA11E5AF1A00163E001C5F&amp;width=600&amp;height=86' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=29D4E5C473CA11E5AF1A00163E001C5F&amp;width=600&amp;height=90' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=29E725FE73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=93' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=29FBEFFC73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=86' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=2A10B1A873CA11E5AF1A00163E001C5F&amp;width=600&amp;height=90' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=2A23C6B273CA11E5AF1A00163E001C5F&amp;width=600&amp;height=98' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3C776BDE73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=107' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3C880F3E73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=99' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3C9AEBF473CA11E5AF1A00163E001C5F&amp;width=600&amp;height=117' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3CAF67C873CA11E5AF1A00163E001C5F&amp;width=600&amp;height=90' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3CC2549673CA11E5AF1A00163E001C5F&amp;width=600&amp;height=85' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3CCECD4873CA11E5AF1A00163E001C5F&amp;width=600&amp;height=87' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3CE33CA673CA11E5AF1A00163E001C5F&amp;width=600&amp;height=90' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3D39659073CA11E5AF1A00163E001C5F&amp;width=600&amp;height=90' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3D5DDECA73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=42' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3D7205F873CA11E5AF1A00163E001C5F&amp;width=600&amp;height=116' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3D85A39273CA11E5AF1A00163E001C5F&amp;width=600&amp;height=98' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3D9B36F873CA11E5AF1A00163E001C5F&amp;width=600&amp;height=99' alt='' /><img src='http://m.kua-jie.com/rest/api/v1.0/file_dir?fileId=3DAF05CA73CA11E5AF1A00163E001C5F&amp;width=600&amp;height=101' alt='' /></div>";
        webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webView.getSettings().setJavaScriptEnabled(true);
//        htmlData = htmlData.replace("<img", "<img width=\"100%\"");
//        webView.loadDataWithBaseURL(null, htmlData, "text/html", "utf-8", null);
        webView.loadUrl("http://m.kua-jie.com/static/" + htmlurl);
//        webView.loadUrl("http://legal.firefox.news.cn/15/1019/08/G0Y8PLKJWO34ZX21.html");
    }

    @Override
    protected void onResume() {
        super.onResume();
        BaseApplication.getInstance().addActivity(WebViewActivity.this);
    }

    @Override
    public <T> void successResponse(T parsedGSON, int tag) {

    }

    @Override
    public void errorResonse(String retmeg, int tag) {
        Toast.makeText(WebViewActivity.this,R.string.noWangluo,Toast.LENGTH_SHORT).show();
    }
    private void showShare() {
        ShareSDK.initSDK(this);
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();
        // 分享时Notification的图标和文字  2.5.9以后的版本不调用此方法
        //oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
        oks.setTitle("豆花新闻");
        // titleUrl是标题的网络链接，仅在人人网和QQ空间使用
        oks.setTitleUrl("http://m.kua-jie.com/static/" + htmlurl);
        // text是分享文本，所有平台都需要这个字段
        oks.setText(title);//我在豆花网app看到一个信息，里面有介绍各种养生食品，你可能有用，发给你看下哦！查看地址：http://m.kua-jie.com/static/" + htmlurl
                // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
//        oks.setImagePath("/mnt/sdcard/zibuyu/erweima.png");//确保SDcard下面存在此张图片
        oks.setImageUrl("http://m.kua-jie.com/static/res/img/douhuawang.png");
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl("http://m.kua-jie.com/static/" + htmlurl);
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("快来评论吧!");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite(getString(R.string.app_name));
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl("http://m.kua-jie.com/static/" + htmlurl);
        // 是否直接分享（true则直接分享）
        oks.setSilent(true);
        // 参考代码配置章节，设置分享参数

        // 启动分享GUI
        oks.show(WebViewActivity.this);

    }





}
